package com.wkw.jkyf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wkw.jkyf.mapper.SupplierMapper;
import com.wkw.jkyf.pojo.Supplier;
import com.wkw.jkyf.service.ISupplierService;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.List;

@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements ISupplierService {

    @Resource
    private SupplierMapper supplierMapper;


    @Override
    public IPage<Supplier> selectSupplierPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Supplier> queryWrapper = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(param)){
            queryWrapper.like("name",param);
        }
        queryWrapper.orderByDesc("id");
        Page<Supplier> page = new Page<>();
        return supplierMapper.selectPage(page,queryWrapper);
    }

    @Override
    public int addsupplier(Supplier supplier) {
        return supplierMapper.insert(supplier);
    }

    @Override
    public int editsupplier(Supplier supplier) {
        return supplierMapper.updateById(supplier);
    }

    @Override
    public Supplier querysupplierById(Integer id) {
        return supplierMapper.selectById(id);
    }

    @Override
    public int deletesupplierById(Integer id) {
        return supplierMapper.deleteById(id);
    }

    @Override
    public List<Supplier> querySupplierList() {
        return supplierMapper.selectList(null);
    }


}
